package com.funny.stock.data.dao.repo;

import com.funny.stock.data.dao.entity.StockDayDataDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StockDayDataRepository extends JpaRepository<StockDayDataDO,Long> {

    @Query(value = "select * from t_stock_day t where t.code= :code and t.date = :date",nativeQuery = true)
    StockDayDataDO queryDate(@Param("code") String code, @Param("date") String date);

    @Query(value = "select * from t_stock_day t where t.code= :code and t.date >= :date",nativeQuery = true)
    List<StockDayDataDO> queryAllByDateAfter(@Param("code") String code, @Param("date") String date);

    @Query(value = "select * from t_stock_day t where t.code= :code and t.date >= :startDate and t.date <= :endDate",nativeQuery = true)
    List<StockDayDataDO> queryAllByDateRange(@Param("code") String code, @Param("startDate") String startDate,@Param("endDate") String endDate);

    @Query(value = "select * from t_stock_day t where t.code= :code and t.date <= :endDate ORDER BY DATE DESC LIMIT 1,1",nativeQuery = true)
    StockDayDataDO queryDayBeforeData(@Param("code") String code, @Param("endDate") String endDate);


    @Query(value = "select * from t_stock_day t where t.code= :code and t.date like :date%",nativeQuery = true)
    List<StockDayDataDO> queryAllByDateLike(@Param("code") String code, @Param("date") String date);

}